"""商城类目页面"""
from selenium.webdriver.common.by import By

from page_objects.base_page import BasePage
from utils.log import logger


class CategoryListPage(BasePage):
    __ADD_SHANGPIN = (By.XPATH, "//*[text()='添加']")
    __MIS_TEXT_ = (By.XPATH, '//p[contains(text(), "创建")]')
    __DELETE_TEXT = (By.XPATH, '//p[contains(text(), "删除")]')
    def click_add(self):
        # 点击添加商品类目
        # self.driver.find_element(By.XPATH, "//*[text()='添加']").click()
        self.do_find(self.__ADD_SHANGPIN).click()

        # ==》进入添加商品类目
        from page_objects.category_create_page import CategoryCreatePage
        return CategoryCreatePage(self.driver)

    def delete_category(self, category_name):
        self.do_find(By.XPATH, f'//*[text()="{category_name}"]/../..//*[text()="删除"]').click()
        return CategoryListPage(self.driver)

    def get_result(self):
        # 获取冒泡信息文本
        # ele = WebDriverWait(self.driver, 10).until(expected_conditions.visibility_of_element_located(By.XPATH, '//p[contains(text(), "创建")]'))
        ele = self.wait_for_visible(self.__MIS_TEXT_)
        ele = ele.text
        logger.info(f"冒泡的信息为：{ele}")
        # ==》返回信息文本
        return ele

    def delete_result(self):
        ele = self.wait_for_visible(self.__DELETE_TEXT)
        ele = ele.text
        logger.info(f"冒泡的信息为：{ele}")
        # ==》返回信息文本
        return ele